import { defineConfig } from 'vite';
import uni from '@dcloudio/vite-plugin-uni';
import autoImport from 'unplugin-auto-import/vite';
import { resolve } from 'path';
export default defineConfig(({ command, mode }) => {
    isDev = ['dev', 'development'].includes(mode);
    return {
        'plugins': [
            uni(),
            autoImport({
                'include': [
                    /\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
                    /\.vue$/,
                    /\.vue\?vue/ // .vue
                ],
                'imports': [
                    'vue',
                    'uni-app'
                ],
                'dts': 'typings/auto-imports.d.ts'
            })
        ],
        'resolve': {
            'alias': [{
                'find': 'src',
                'replacement': resolve(__dirname, 'src')
            },
            {
                'find': '~@',
                'replacement': resolve(__dirname, 'src')
            }
            ],
            'extensions': ['.js', '.vue', 'css', 'less', '.json', '.mjs', '.ts', '.jsx', '.tsx']
        },
        'css': {
            'preprocessorOptions': {
                'less': {
                    'javascriptEnabled': true,
                    'additionalData': `
					@import "${resolve(__dirname, 'src/assets/less/global.less')}";
					@import "${resolve(__dirname, 'src/assets/less/common.less')}";
					@import "${resolve(__dirname, 'src/plugins/themes/index.less')}";
				`
                }
            }
        },
        'esbuild': {
            'drop': isDev ? [] : ['console', 'debugger']
        },
        'build': {
            'rollupOptions': {
                'output': {}
            }
        },
        'server': {
            'port': 5173,
            'host': '0.0.0.0',
            'proxy': {
                '/api': {
                    'target': 'http://127.0.0.1:8080',
                    'ws': true,
                    'changOrigin': true,
                    'rewrite': path => path.replace(/^\/api/, '')
                }
            }
        }
    };
});